package trash;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import ua.javatr.android.smb.R;

/**
 * Created by Вячеслав on 09.06.2014.
 */

public class CustomGridViewRowAdapter extends BaseAdapter {

    private Activity activity;
    private Integer[] thumbnails;
    private String[] labels;

    CustomGridViewRowAdapter(Activity activity, Integer[] thumbnails, String[] labels) {
        this.activity = activity;
        this.thumbnails = thumbnails;
        this.labels = labels;
    }

    public static class ViewHolder {
        public ImageView thumbnail;
        public TextView label;
    }

    @Override
    public int getCount() {
        return thumbnails.length;
    }

    @Override
    public Object getItem(int i) {
        return labels[i];
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        LayoutInflater inflater = activity.getLayoutInflater();
        if (view == null) {
            viewHolder = new ViewHolder();
            view = inflater.inflate(R.layout.gridview_customrow, null);
            viewHolder.label = (TextView) view.findViewById(R.id.tvLabel);
            viewHolder.thumbnail = (ImageView) view.findViewById(R.id.ivThumbnail);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.label.setText(labels[i]);
        viewHolder.thumbnail.setImageResource(thumbnails[i]);
        return view;
    }
}
